// utils/component/bingo/bingo.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    animationJar: null,
    imageShow: true,
    isShow: false,
    multiple: "0",
    count: "10",
  },

  ready: function() {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    beginAnimation() {
      var innerAudioContext = wx.createInnerAudioContext()
      innerAudioContext.autoplay = true
      innerAudioContext.src = '/images/common/bingo.mp3'
      innerAudioContext.onPlay(() => {
        console.log('开始播放')
      })
      innerAudioContext.onError((res) => {
        console.log(res.errMsg)
        console.log(res.errCode)
      })

      var that = this
      setTimeout(function () {
        that.setData({ imageShow: false })
        that.textAnimation()
      }, 800)
      setTimeout(function () {
        that.cashAnimation()
      }, 2000)
      setTimeout(function () {
        // innerAudioContext.onStop()
        that.dismiss()
      }, 3400)
    },
    reloadAnimation() {
      var animation = wx.createAnimation({
        timingFunction: 'ease-out',
      })

      animation.translateY(0).opacity(0).step();
      animation.opacity(0).step({ duration: 2000 })
      
      var cashAnimation = wx.createAnimation({
        timingFunction: 'ease-out',
      })

      cashAnimation.opacity(1).step()
      this.setData({
        animationJar: animation.export(),
        cashAnimation: cashAnimation.export(),
        imageShow: true,
      })
    },
    textAnimation() {
      //实例化一个动画
      var animation = wx.createAnimation({
        timingFunction: 'ease-out',
      })

      animation.translateY(-150).opacity(1).step({duration: 1200});
      animation.translateY(-180).step({duration: 1700})
      animation.opacity(0).step({ duration: 2000 })
      this.setData({ animationJar: animation.export() })
    },
    cashAnimation() {
      //实例化一个动画
      var cashAnimation = wx.createAnimation({
        timingFunction: 'ease-out',
      })

      cashAnimation.opacity(0).step({ duration: 1000 })
      this.setData({ cashAnimation: cashAnimation.export() })
    },
    show(multiple, count) {
      this.setData({ 
        isShow: true,
        multiple: multiple,
        count: count
        })
      this.beginAnimation()
    },
    dismiss() {
      this.setData({ isShow: false })
      this.reloadAnimation()
    }
  }
})
